package com.itheima.health.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.service.CheckitemService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("checkitem")
public class CheckitemController {

    @Reference
    private CheckitemService checkitemService;
    @RequestMapping("add")
    public Result add(@RequestBody CheckItem checkItem){
        try {
            checkitemService.add(checkItem);
            return new Result(true, MessageConst.ADD_CHECKITEM_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConst.ADD_CHECKITEM_FAIL);
        }

    }
    @RequestMapping("findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){

        try {
            //调用service  返回PageResult
            PageResult pageResult=  checkitemService.pageQuery(queryPageBean);
            //返回成功把PageResult给前端页面
            return pageResult;
            //失败展示为Null
        } catch (Exception e) {
            e.printStackTrace();
            return new PageResult(0L,null);
        }
    }
}
